﻿using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;

namespace Elvex
{
    public abstract class HUD
    {
        //public GameObject 

        public abstract string ResourcePath { get; }

        public Transform Parent { get; private set; }

        public Vector3 OffsetPosition { get; private set; }

        public Transform Transform { get; private set; }

        public static T Create<T>(Transform parent, Vector3 offsetposition) where T : HUD, new()
        {
            T hud = new T();
            hud.Parent = parent;
            hud.OffsetPosition = offsetposition;
            return hud;
        }

        public bool Show()
        {
            if( null == Transform)
            {
                GameObject go = Object.Instantiate(Resources.Load(ResourcePath), HUDCanvas.HUDLayout.position, HUDCanvas.HUDLayout.rotation, HUDCanvas.HUDLayout) as GameObject;
                Transform = go.transform;
                Vector3 screenpos = Camera.main.WorldToScreenPoint(Parent.position + OffsetPosition);
                Transform.localPosition = HUDCamera.ScreenToWorldPoint(screenpos);
            }
            Transform.gameObject.SetActive(true);
            return true;
        }

    }
}
